<?php
if (isset($_POST['n'])){
    include 'config.php';
    $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
    if (!$mysqli->set_charset("utf8")) {}
    
    $name=addslashes(trim($_POST['n']));
    
    $condition=' where title like "%'.$name.'%" or sanchang like "%'.$name.'%" ';
    if (preg_match("/设计/", $name)) {
        $condition.=' or skill_type=1 ';
    }
    if (preg_match("/摄制/", $name)) {
        $condition.=' or skill_type=2 ';
    }
    if (preg_match("/文案/", $name)) {
        $condition.=' or skill_type=3 ';
    }
    if (preg_match("/综合/", $name)) {
        $condition.=' or skill_type=21 ';
    }
    
    
    
    $condOrder=' order by workyear desc ';
    if (isset($_POST['oid'])){
        if(1 == $_POST['oid']){
            $condOrder=' order by workyear desc ';
        }
        if(2 == $_POST['oid']){
            $condOrder=' order by id desc ';
        }
    }
    
    
    
    $query=$mysqli->query("SELECT workyear,id,title,photo,subtitle,star,price FROM zhi_supplier ".$condition." ".$condOrder);
    
    $data=array();
    while ($list=$query->fetch_assoc()){
        $price=(int)$list['price'];
        if(0 == $price){
            $list['price']=0;
        }
        $data[]=array('workyear'=>$list['workyear'],'id'=>$list['id'],'title'=>$list['title'],'photo'=>$list['photo'],
            'subtitle'=>$list['subtitle'],'star'=>$list['star'],'price'=>$list['price']);
    }
    $mysqli->close();
    echo json_encode($data);
}

